package com.admin.business.venusSysMenu;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 权限菜单表
 * @create: 2022-07-08 19:04:49
 **/
@Service("venusSysMenu")
@Slf4j
public class VenusSysMenuService{

    @Resource
    VenusSysMenuDao venusSysMenuDao;

    /**
     * 添加权限菜单表,获取menu_id数据
     *
     * @param cdoRequest - menu_id:
     *                   - menu_name:
     *                   - menu_parent_id:
     *                   - remark:
     *                   - menu_url:菜单链接
     *                   - menu_sort:菜单排序
     *                   - menu_logo:菜单logo
     *                   - menu_type:1菜单权限，2功能权限，3数据权限
     *                   - menu_status:1正常，2禁用
     *                   - menu_company_type:1物业公司用，2本公司管理平台用
     *                   - menu_permission:授权标识
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return addVenusSysMenu(CDO cdoRequest) {
        venusSysMenuDao.addVenusSysMenu(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("menu_id")) {
            cdoResult.set("menu_id", cdoRequest.get("menu_id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据menu_id，更新权限菜单表数据
     *
     * @param cdoRequest - menu_id:
     *                   - menu_name:
     *                   - menu_parent_id:
     *                   - remark:
     *                   - menu_url:菜单链接
     *                   - menu_sort:菜单排序
     *                   - menu_logo:菜单logo
     *                   - menu_type:1菜单权限，2功能权限，3数据权限
     *                   - menu_status:1正常，2禁用
     *                   - menu_company_type:1物业公司用，2本公司管理平台用
     *                   - menu_permission:授权标识
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return updateVenusSysMenuById(CDO cdoRequest) {
        int affectedRows = venusSysMenuDao.updateVenusSysMenuById(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据menu_id，删除权限菜单表数据
     *
     * @param cdoRequest - menu_id:
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return deleteVenusSysMenuById(CDO cdoRequest){
        int affectedRows = venusSysMenuDao.deleteVenusSysMenuById(cdoRequest.getInteger("menu_id"));
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除权限菜单表数据
     *
     * @param cdoRequest - menu_name:
     *                   - menu_parent_id:
     *                   - menu_type:1菜单权限，2功能权限，3数据权限
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return deleteVenusSysMenu(CDO cdoRequest) {
        int affectedRows = venusSysMenuDao.deleteVenusSysMenu(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取权限菜单表数据
     *
     * @param cdoRequest - menu_id:
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return getVenusSysMenuById(CDO cdoRequest) {
        CDO cdoMapperResult = venusSysMenuDao.getVenusSysMenuById(cdoRequest.getInteger("menu_id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据混合条件，获取权限菜单表数据
     *
     * @param cdoRequest - menu_id:
     *                   - menu_name:
     *                   - menu_parent_id:
     *                   - menu_type:1菜单权限，2功能权限，3数据权限
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return getVenusSysMenu(CDO cdoRequest) {
        CDO cdoMapperResult = venusSysMenuDao.getVenusSysMenu(cdoRequest);
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取权限菜单表数据列表
     *
     * @param cdoRequest - menu_name:
     *                   - menu_parent_id:
     *                   - menu_type:1菜单权限，2功能权限，3数据权限
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return getVenusSysMenuList(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysMenuDao.getVenusSysMenuList(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysMenuDao.getVenusSysMenuListCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据混合条件，获取权限菜单表数据列表
     *
     * @param cdoRequest - menu_id:
     *                   - menu_name:
     *                   - menu_parent_id:
     *                   - menu_type:1菜单权限，2功能权限，3数据权限
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return getVenusSysMenuListByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysMenuDao.getVenusSysMenuListByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysMenuDao.getVenusSysMenuListByConditionCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
